<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>命令模式：解耦请求的艺术</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .content-card {
            background: rgba(255, 255, 255, 0.95);
            backdrop-filter: blur(10px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 25px 50px rgba(0, 0, 0, 0.15);
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 80%;
            background: linear-gradient(to bottom, #667eea, #764ba2);
            border-radius: 2px;
        }
        
        .code-block {
            background: #1e1e1e;
            color: #d4d4d4;
            border-radius: 8px;
            padding: 20px;
            overflow-x: auto;
            font-family: 'Consolas', 'Monaco', monospace;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        
        .feature-card {
            background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
            color: white;
            padding: 30px;
            border-radius: 15px;
            transition: transform 0.3s ease;
        }
        
        .feature-card:hover {
            transform: scale(1.05);
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 30px 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-family: 'Noto Serif SC', serif;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
        }
        
        .highlight-box {
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            padding: 20px;
            border-radius: 10px;
            margin: 20px 0;
            border-left: 4px solid #ff6b6b;
        }
        
        .icon-feature {
            display: inline-flex;
            align-items: center;
            justify-content: center;
            width: 50px;
            height: 50px;
            background: linear-gradient(135deg, #667eea, #764ba2);
            border-radius: 50%;
            color: white;
            margin-right: 15px;
            flex-shrink: 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <div class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-6 animate-pulse">
                <i class="fas fa-terminal mr-4"></i>命令模式
            </h1>
            <p class="text-2xl md:text-3xl mb-8 opacity-90">解耦请求的艺术</p>
            <div class="max-w-3xl mx-auto">
                <p class="text-lg leading-relaxed opacity-80">
                    在软件架构的世界里，命令模式如同一位优雅的指挥家，将请求的发送者与接收者完美解耦，
                    让系统在复杂的交互中保持优雅与灵活。
                </p>
            </div>
        </div>
    </div>

    <!-- Main Content -->
    <div class="container mx-auto px-6 py-12">
        <!-- Introduction Section -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-lightbulb text-yellow-500 mr-3"></i>命令模式的实现机制
            </h2>
            <div class="prose max-w-none">
                <p class="text-lg leading-relaxed text-gray-700 mb-6">
                    <span class="drop-cap">命</span>令模式是一种行为设计模式，它允许将请求封装为对象，从而使得我们可以对请求进行参数化、延迟执行、支持撤销和重做等操作。这种模式的核心在于将请求的发送者与接收者解耦，从而提高系统的灵活性和可扩展性。
                </p>
                <div class="highlight-box">
                    <p class="text-gray-800">
                        <i class="fas fa-info-circle mr-2"></i>
                        在当今的软件开发中，尤其是在构建复杂的事件驱动系统时，命令模式的价值尤为突出。事件驱动架构强调异步处理和响应性，而命令模式则为我们提供了一种简洁且高效的方式来管理这些异步事件。
                    </p>
                </div>
            </div>
        </div>

        <!-- Pattern Structure Visualization -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-sitemap text-blue-500 mr-3"></i>模式结构可视化
            </h2>
            <div class="mermaid">
                graph TB
                    Client[客户端 Client]
                    Invoker[调用者 Invoker]
                    Command[命令接口 Command]
                    ConcreteCommand[具体命令 ConcreteCommand]
                    Receiver[接收者 Receiver]
                    
                    Client -->|创建| ConcreteCommand
                    Client -->|设置命令| Invoker
                    Invoker -->|调用| Command
                    ConcreteCommand -.->|实现| Command
                    ConcreteCommand -->|执行| Receiver
                    
                    style Client fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                    style Invoker fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                    style Command fill:#f093fb,stroke:#fff,stroke-width:2px,color:#fff
                    style ConcreteCommand fill:#f5576c,stroke:#fff,stroke-width:2px,color:#fff
                    style Receiver fill:#4facfe,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </div>

        <!-- Components Section -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
            <div class="content-card rounded-2xl p-8">
                <h3 class="text-2xl font-bold mb-4 text-gray-800">
                    <div class="icon-feature">
                        <i class="fas fa-puzzle-piece"></i>
                    </div>
                    核心组件
                </h3>
                <ul class="space-y-4">
                    <li class="flex items-start">
                        <i class="fas fa-chevron-right text-purple-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">命令接口（Command）</strong>
                            <p class="text-gray-600 mt-1">定义执行操作的统一接口，所有具体命令都需实现此接口。</p>
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-chevron-right text-purple-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">具体命令（ConcreteCommand）</strong>
                            <p class="text-gray-600 mt-1">实现命令接口，封装对接收者的调用。</p>
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-chevron-right text-purple-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">接收者（Receiver）</strong>
                            <p class="text-gray-600 mt-1">执行具体业务逻辑的对象。</p>
                        </div>
                    </li>
                </ul>
            </div>
            
            <div class="content-card rounded-2xl p-8">
                <h3 class="text-2xl font-bold mb-4 text-gray-800">
                    <div class="icon-feature">
                        <i class="fas fa-star"></i>
                    </div>
                    核心优势
                </h3>
                <ul class="space-y-4">
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">解耦设计</strong>
                            <p class="text-gray-600 mt-1">请求发送者与接收者完全解耦，提高系统灵活性。</p>
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">撤销/重做</strong>
                            <p class="text-gray-600 mt-1">轻松实现操作的撤销和重做功能。</p>
                        </div>
                    </li>
                    <li class="flex items-start">
                        <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                        <div>
                            <strong class="text-gray-800">命令队列</strong>
                            <p class="text-gray-600 mt-1">支持命令的排队和异步执行。</p>
                        </div>
                    </li>
                </ul>
            </div>
        </div>

        <!-- Implementation Example -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-code text-green-500 mr-3"></i>实现示例
            </h2>
            
            <div class="mb-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">1. 定义命令接口</h3>
                <div class="code-block">
                    <pre><code>public interface Command {
    void execute();
}</code></pre>
                </div>
            </div>
            
            <div class="mb-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">2. 实现具体命令</h3>
                <div class="code-block">
                    <pre><code>public class LightOnCommand implements Command {
    private Light light;

    public LightOnCommand(Light light) {
        this.light = light;
    }

    @Override
    public void execute() {
        light.turnOn();
    }
}</code></pre>
                </div>
            </div>
            
            <div class="mb-8">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">3. 定义接收者</h3>
                <div class="code-block">
                    <pre><code>public class Light {
    public void turnOn() {
        System.out.println("Light is ON");
    }

    public void turnOff() {
        System.out.println("Light is OFF");
    }
}</code></pre>
                </div>
            </div>
        </div>

        <!-- Event-Driven Applications -->
        <div class="content-card rounded-2xl p-8 mb-12">
            <h2 class="section-title text-3xl font-bold mb-6 text-gray-800">
                <i class="fas fa-bolt text-yellow-500 mr-3"></i>事件驱动系统中的应用
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="feature-card">
                    <i class="fas fa-unlink text-4xl mb-4"></i>
                    <h3 class="text-xl font-bold mb-2">事件解耦</h3>
                    <p>事件产生者与处理者松散耦合，提高系统灵活性。</p>
                </div>
                
                <div class="feature-card">
                    <i class="fas fa-sync-alt text-4xl mb-4"></i>
                    <h3 class="text-xl font-bold mb-2">异步处理</h3>
                    <p>支持命令排队和异步执行，提升系统